package com.xtwy.admin.web.service.impl;

import com.github.pagehelper.PageHelper;
import com.xtwy.admin.web.mapper.AdminMapper;
import com.xtwy.admin.web.model.pojo.Admin;
import com.xtwy.admin.web.service.AdminService;
import com.xtwy.common.utils.CamelCaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 类的描述：
 *
 * @作者: 侯建军
 * @邮箱: 474177818@qq.com
 * @博客: https://blog.csdn.net/marquis888
 * @创建日期: 2018年11月18日  13:20
 * @版本: v1.0
 * @jdk版本使用: JDK1.8
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    public List<Admin> getPageList(Admin admin) {
        PageHelper.offsetPage(1, 10);
        String orderBy="updated_at desc";
        PageHelper.startPage(0, 10, orderBy);
        return adminMapper.selectAll();
    }

    public Integer getCount(Example example) {
        return adminMapper.selectCountByExample(example);
    }

    public Admin getById(String id)
    {
        return adminMapper.selectByPrimaryKey(id);
    }

    public Admin findByUsername(String username) {

        return adminMapper.selectByUsername(username);
    }

    public void deleteById(String id) {
        adminMapper.deleteByPrimaryKey(id);
    }

    public void insert(Admin admin) {
        adminMapper.insert(admin);
    }

    public void save(Admin admin) {
        if (admin.getUid() != null) {
            adminMapper.updateByPrimaryKey(admin);
        } else {
            adminMapper.insert(admin);
        }
    }

    public void updateExample(Admin admin, Example example) {
        adminMapper.updateByExampleSelective(admin, example);
    }

}
